package org.example;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;

public class TEST3 {

    public static void main(String[] args) throws InterruptedException {

        String s= "1777895548578131969\n" +
                "1778621487663362050\n" +
                "1779218748634116097\n" +
                "1780749740276547586\n" +
                "1783007458752258055\n" +
                "1783007458756452354\n" +
                "1783007459612090380\n" +
                "1783405431340457986\n" +
                "1784068035011641345\n" +
                "1785209591002095620\n" +
                "1786606637260177409\n" +
                "1788364114905497603\n" +
                "1791663948555059202\n" +
                "1792380726777012226\n" +
                "1792380726777012227\n" +
                "1794971185637683202\n" +
                "1795021192327786515\n" +
                "1795021192331980805\n" +
                "1797543920143278082\n" +
                "1800786715732799500\n" +
                "1800786715736993800\n" +
                "1800786716601020419\n" +
                "1800786717439881217\n" +
                "1800786718366822410\n" +
                "1801455329151393797\n" +
                "1801457135742984193\n" +
                "1801838333862453250\n" +
                "1802707949262315522\n" +
                "1802707949266509826\n" +
                "1803699619712917506\n" +
                "1803706483209068548\n" +
                "1803726118391238657\n" +
                "1804009780830724098\n" +
                "1805797058041339909\n" +
                "1806515568916815874\n" +
                "1808844915497431044\n" +
                "1810856518669537281\n" +
                "1812807452865826836\n" +
                "1812807452870021129\n" +
                "1814127197939425282\n" +
                "1816023466457939969";
        //按照换行符分割
        String[] split = s.split("\n");
        //定义一个新的字符串
        for (String taskId : split) {
            String s1="http://bi-admin.baishucloud.com/datalink-api/admin-api/bi/ding-dataset-task/back/page?pageNo=1" +
                    "&pageSize=10&corpName=&taskStatus=&syncStatus=&" +
                    "id="+taskId+"&code=";
            //发送 get 请求
            HttpRequest get = HttpUtil.createGet(s1);
            //设置token
            get.header("Authorization","Bearer 41a8e43084de4307be73798d21e34d4a");
            //获取返回的结果
            String body = get.execute().body();
            //打印结果
            //解析结果
            JSONObject jsonObject = new JSONObject(body);
            JSONArray byPath = (JSONArray) jsonObject.getByPath("data.list");
            if(byPath.size()>0){
                JSONObject jsonObject1 = (JSONObject) byPath.get(0);

                String url= "http://bi-admin.baishucloud.com/datalink-api/admin-api/bi/ding-dataset-task/syncData";
                HttpRequest post = HttpUtil.createPost(url);
                post.header("Authorization","Bearer 41a8e43084de4307be73798d21e34d4a");
                //设置请求体
                post.body("{\n" +
                        "    \"syncDataStatus\": \"0\",\n" +
                        "    \"taskId\": \""+taskId+"\",\n" +
                        "    \"startTimeOfIncrementalSync\": 1722355200583,\n" +
                        "    \"endTimeOfIncrementalSync\": 1724947199583\n" +
                        "}");
                //发送请求
                String body1 = post.execute().body();
                JSONObject jsonObject2 = new JSONObject(body1);
                System.out.println(jsonObject2);
                Thread.sleep(10*1000);
            }
        }


    }
}
